"""
Output arguments.
"""

{% import "_components.jinja" as _components %}

from __future__ import annotations

from abc import ABC, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Any

{{ _components.import_all(template_path, import_nodes=False) }}

if TYPE_CHECKING:
    from ..nodes import FilterableStream, OutputNode, OutputStream

class OutputArgs(ABC):
    """Output arguments interface."""

    @abstractmethod
    def _output_node(self, *streams: FilterableStream, filename: str | Path, **kwargs: Any) -> OutputNode:
        ...

    def output(
        self,
        *streams: "FilterableStream",
        filename: str | Path,
        {%- for option in options -%}
        {%- if option.is_output_option -%}
        {{ option.name | option_name_safe }}: {{ option | option_typing }} = None,
        {%- endif -%}
        {%- endfor -%}
        encoder_options: FFMpegEncoderOption | None = None,
        muxer_options: FFMpegMuxerOption | None = None,
        format_options: FFMpegAVFormatContextEncoderOption | None = None,
        codec_options: FFMpegAVCodecContextEncoderOption | None = None,
        extra_options: dict[str, Any] | None = None,
    ) -> OutputStream:
        """
        Output file URL

        Args:
            *streams: the streams to output
            filename: the filename to output to
            {% for option in options %}
            {%- if option.is_output_option -%}
            {{option.name | option_name_safe}}: {{option.help | normalize_help_text}}
            {% endif %}
            {%- endfor -%}
            encoder_options: ffmpeg's encoder options
            muxer_options: FFMpegMuxerOption
            format_options: FFMpegAVFormatContextEncoderOption
            codec_options: FFMpegAVCodecContextEncoderOption
            extra_options: the arguments for the output

        Returns:
            the output stream
        """

        return self._output_node(*streams, filename=filename, **merge({
            {% for option in options %}
                {%- if option.is_output_option -%}
                "{{ option.name}}": {{ option.name | option_name_safe }},
                {% endif %}
            {% endfor %}
        }, encoder_options, muxer_options, format_options, codec_options, extra_options)).stream()
